/*************************************************************************
	> File Name: monolith/eigen/eigen.h
	> Author: dzhang
	> Mail: dong.zhang@ingenic.com 
	> Created Time: Wed 16 Dec 2020 04:37:23 PM CST
 ************************************************************************/

#ifndef _MONOLITH_EIGEN_EIGEN_H_
#define _MONOLITH_EIGEN_EIGEN_H_
#include <iostream>
#include <vector>
#include "Eigen/Dense"
#include "unsupported/Eigen/CXX11/Tensor"
#include "monolith/core/macros.h"
CC_NAME_SPACE_BEGIN

namespace eigen{


template<class T, int Rank, int ORank = Rank>
Eigen::Tensor<T, Rank, Eigen::RowMajor> tanspose(Eigen::Tensor<T, Rank, Eigen::RowMajor> src_tensor, std::vector<int32> permutation){
    Eigen::array<Eigen::DenseIndex, ORank> shuffle;
    for(int i = 0; i < permutation.size(); i++){
        shuffle[i] = permutation[i];
    }
    Eigen::Tensor<T, ORank, Eigen::RowMajor> dst_tensor = src_tensor.shuffle(shuffle);
    return dst_tensor;
}

template<class T, int Rank, int ORank = Rank>
Eigen::Tensor<T, ORank, Eigen::RowMajor> reshape(Eigen::Tensor<T, Rank, Eigen::RowMajor> src_tensor, std::vector<int32> permutation){
    Eigen::array<Eigen::DenseIndex, ORank> dst_dims;
    for(int i = 0; i < permutation.size(); i++){
        dst_dims[i] = permutation[i];
    }
    Eigen::Tensor<T, ORank, Eigen::RowMajor> dst_tensor = src_tensor.reshape(dst_dims);
    return dst_tensor;
}









}



CC_NAME_SPACE_END
#endif //_MONOLITH_EIGEN_EIGEN_H
